﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RoutesManager.aspx.cs" Inherits="GPSTrackingWebsiteManager.Pages.RoutesManager" %>

<!DOCTYPE html>
<link href="../Css/GPSTrackingWebsite.css" rel="stylesheet" />
<script src="../Javascript/WindowMessageManager.js"></script>
<script src="../Javascript/ObjectsV2.js"></script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Administrador de Rutas</title>
</head>
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
    <script type="text/javascript">

        var opener = GetRadWindow();
        var RoutesManager = new RoutesManager();
        var Companies = new Companies();
        var lenghMsg = 450;
        

        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow)
                oWindow = window.radWindow;
            else if (window.frameElement.radWindow)
                oWindow = window.frameElement.radWindow;
            return oWindow.BrowserWindow;
        }

        function loadInfo() {
            getCompaniesByAdmin();
        }

        function getCompaniesByAdmin() {
            requestStart(getrpvRoutesManagerPanelUpdateControl());
            PageMethods.wsGetCompaniesByAdminUsername(getCompaniesByAdminOk, getCompaniesByAdminError);
        }

        function getCompaniesByAdminOk(object) {
            Companies.openXMLCompaniesByAdminUsername(object, opener.globalRoutesManager.companiesList);
            Companies.loadCompaniesDataSource(getCompaniesGrid(), opener.globalRoutesManager.companiesList, opener.globalRoutesManager.companiesDataSource);
            if (opener.globalRoutesManager.companiesList.length == 1) {
                getCompaniesGrid().selectItem(0);
                opener.globalRoutesManager.companyIDSelected = opener.globalRoutesManager.companiesList[0].companyID;
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
            }
            else {
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
            }
        }

        function getCompaniesByAdminError(error) {
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
            msgError(error.get_message(), titles.routesAdministrator);
        }

        function CompaniesGrid_OnRowClick(sender, args) {
            var index = Companies.getIndexCompanyID(args.getDataKeyValue("CompanyID"));
            if (index != -1) {
                opener.globalRoutesManager.companyIDSelected = args.getDataKeyValue("CompanyID")
                getDepartmentsByCompanyID();
                getClientsByCompanyID();
            }
        }

        function getDepartmentsByCompanyID() {
            requestStart(getrpvRoutesManagerPanelUpdateControl());
            PageMethods.wsGetAllDepartmentsByCompanyIDAndAdminUsername(opener.globalRoutesManager.companyIDSelected, getDepartmentsByCompanyIDOk, getDepartmentsByCompanyIDError);
        }

        function getDepartmentsByCompanyIDOk(object) {

            clearList(opener.globalRoutesManager.usersGroupsList);
            clearDataSource(opener.globalRoutesManager.usersGroupsDataSource, getUsersGroupsGrid(), true);

            clearList(opener.globalRoutesManager.usersList);
            clearDataSource(opener.globalRoutesManager.usersDataSource, getUsersRoutesGrid(), true);

            clearList(opener.globalRoutesManager.gpsImeiList);
            clearDataSource(opener.globalRoutesManager.gpsImeiDataSource, getGpsRoutesGrid(), true);
            

            opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, null);
            opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, null);
            opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);



            RoutesManager.openXMLDepartmentsByCompanyID(object, opener);
            RoutesManager.loadDepartmentsDataSource(getDeparmentsGrid(), opener);
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
        }

        function getDepartmentsByCompanyIDError(error) {
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
            msgError(error.get_message(), titles.routesAdministrator);
        }

        function getClientsByCompanyID() {
            requestStart(getrpvRoutesManagerPanelUpdateControl());
            PageMethods.wsGetClientsByCompanyID(opener.globalRoutesManager.companyIDSelected, getClientsByCompanyIDOk, getClientsByCompanyIDError);
        }

        function getClientsByCompanyIDOk(object) {
            RoutesManager.clearClientsMarkers(opener);
            opener.globalRoutesManager.gpsImeiSelected = -1;
            RoutesManager.openXMLAllClientsByCompanyID(object, opener.globalRoutesManager.allClientsList, opener.objMapControl);
            //RoutesManager.loadAllClientsByCompanyIDDataSource(getClientsRoutesGrid(), opener.globalRoutesManager.allClientsList, opener.globalRoutesManager.allClientsDataSource, opener);
            refreshAllClients();
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
        }
        
        function getClientsByCompanyIDError(error) {
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
            msgError(error.get_message(), titles.routesAdministrator);
        }

        function DepartmentsGrid_OnRowClick(sender, args) {
            var index = RoutesManager.getIndexDepartmentID(opener.globalRoutesManager.departmentsList, args.getDataKeyValue("DepartmentID"));
            if (index != -1) {
                opener.globalRoutesManager.departmentIDSelected = args.getDataKeyValue("DepartmentID")
                getUsersGroupsByDepartmentID();
            }
        }

        function getUsersGroupsByDepartmentID() {
            requestStart(getrpvRoutesManagerPanelUpdateControl());
            PageMethods.wsGetAllUsersGroupsByDepartmentID(opener.globalRoutesManager.departmentIDSelected, getUsersGroupsByDepartmentIDOk, getUsersGroupsByDepartmentIDError);
        }

        function getUsersGroupsByDepartmentIDOk(object) {

            clearList(opener.globalRoutesManager.usersList);
            clearDataSource(opener.globalRoutesManager.usersDataSource, getUsersRoutesGrid(), true);

            clearList(opener.globalRoutesManager.gpsImeiList);
            clearDataSource(opener.globalRoutesManager.gpsImeiDataSource, getGpsRoutesGrid(), true);

            opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, null);
            opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, null);
            opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);

            RoutesManager.openXMLUsersGroupsByDepartmentID(object, opener);
            RoutesManager.loadUsersGroupsDataSource(getUsersGroupsGrid(), opener);
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
        }

        function getUsersGroupsByDepartmentIDError(error) {
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
            msgError(error.get_message(), titles.routesAdministrator);
        }

        function UsersGroupsGrid_OnRowClick(sender, args) {
            var index = RoutesManager.getIndexUserGroupID(opener.globalRoutesManager.usersGroupsList, args.getDataKeyValue("UserGroupID"));
            if (index != -1) {
                opener.globalRoutesManager.userGroupIDSelected = args.getDataKeyValue("UserGroupID")
                getAllUsersByUserGroupID();
            }
        }
                
        function getAllUsersByUserGroupID() {
            requestStart(getrpvRoutesManagerPanelUpdateControl());
            PageMethods.wsGetUsersByUserGroupID(opener.globalRoutesManager.userGroupIDSelected, getAllUsersByUserGroupIDOk, getAllUsersByUserGroupIDError);
        }

        function getAllUsersByUserGroupIDOk(object) {
            clearList(opener.globalRoutesManager.usersList);
            clearDataSource(opener.globalRoutesManager.usersDataSource, getUsersRoutesGrid(), true);

            clearList(opener.globalRoutesManager.gpsImeiList);
            clearDataSource(opener.globalRoutesManager.gpsImeiDataSource, getGpsRoutesGrid(), true);

            opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, null);
            opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, null);
            opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);

            RoutesManager.openXMLUsersByUserGroupID(object, opener);
            RoutesManager.loadUsersRouteByUserGroupIDDataSource(getUsersRoutesGrid(), opener);
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
        }

        function getAllUsersByUserGroupIDError(error) {
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
            msgError(error.get_message(), titles.routesAdministrator);
        }

        function UsersRoutesGrid_OnRowClick(sender, args) {

            var username = args.getDataKeyValue("Username");

            //if (opener.globalRoutesManager.usernameSelected != username) {
            opener.globalRoutesManager.usernameSelected = username;
            getImeiByUser();
            //}
        }

        function getImeiByUser() {
            requestStart(getrpvRoutesManagerPanelUpdateControl());
            PageMethods.wsGetImeiByUser(opener.globalRoutesManager.companyIDSelected, opener.globalRoutesManager.usernameSelected, getImeiByUserOk, getImeiByUserError);
        }

        function getImeiByUserOk(object) {
            clearList(opener.globalRoutesManager.gpsImeiList);
            clearDataSource(opener.globalRoutesManager.gpsImeiDataSource, getGpsRoutesGrid(), true);

            opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, null);
            opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, null);
            opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);

            RoutesManager.openXMLImeiByUser(object, opener);
            RoutesManager.loadImeiDataSource(getGpsRoutesGrid(), opener);
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
        }

        function getImeiByUserError(error) {
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
            msgError(error.get_message(), titles.routesAdministrator);
        }

        function GpsRoutesGrid_OnRowClick(sender, args) {
            var imei = args.getDataKeyValue("GPSImei");
            var index = -1;

            if (opener.globalRoutesManager.gpsImeiSelected != imei) {
                opener.globalRoutesManager.gpsImeiSelected = imei;

                index = getIndexGpsImei(opener.globalRoutesManager.gpsImeiList, imei);
                if (index != -1) {
                    opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, opener.globalRoutesManager.gpsImeiList[index].position);
                    opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, opener.globalRoutesManager.gpsImeiList[index].image);
                    opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, true);
                    opener.objMapControl.setTitleMarker(opener.objMapControl.originImeiMarker, opener.globalRoutesManager.gpsImeiList[index].name);
                    opener.objMapControl.setCenterMap(opener.globalRoutesManager.gpsImeiList[index].position);
                }
                else {
                    opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, null);
                    opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, null);
                    opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);
                }

                getGpsRoutesGrid().clearSelectedItems();
                /*for (i = 0; i < opener.globalRoutesManager.allClientsList.length; i++) {
                    opener.globalRoutesManager.allClientsList[i].checked = false;
                }*/
                RoutesManager.loadAllClientsByCompanyIDDataSource(getClientsRoutesGrid(), opener.globalRoutesManager.allClientsList, opener.globalRoutesManager.allClientsDataSource, opener);//loadCustomersGroupsRoutesDataSource();
            }
            else {
                index = getIndexGpsImei(opener.globalRoutesManager.gpsImeiList, opener.globalRoutesManager.gpsImeiSelected);
                
                if (index != -1) {
                    opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, opener.globalRoutesManager.gpsImeiList[index].position);
                    opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, opener.globalRoutesManager.gpsImeiList[index].image);
                    opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, true);
                    opener.objMapControl.setTitleMarker(opener.objMapControl.originImeiMarker, opener.globalRoutesManager.gpsImeiList[index].name);
                    opener.objMapControl.setCenterMap(opener.globalRoutesManager.gpsImeiList[index].position);
                }
                else {
                    opener.objMapControl.setPositionMarker(opener.objMapControl.originImeiMarker, null);
                    opener.objMapControl.setIconMarker(opener.objMapControl.originImeiMarker, null);
                    opener.objMapControl.setVisibleMarker(opener.objMapControl.originImeiMarker, false);
                }
            }
        }

        function ClientsRoutesGrid_RowSelecting(sender, args) {
            RoutesManager.clientsRoutesGridRowSelection(args, opener);
        }

        function ClientsRoutesGrid_RowDeselecting(sender, args) {
            RoutesManager.clientsRoutesGridRowDeselecting(args, opener);
        }

        function ClientsRoutesSelectedGrid_OnRowClick(sender, args) {
            var index = -1;
            if (args._domEvent.target.cellIndex == 0) {// La columna 0 Representa la columna de eliminar
                index = RoutesManager.getIndexClientID(opener.globalRoutesManager.allClientsList, args.getDataKeyValue("ClientID"));
                if (index != -1) {
                    if (confirm('¿Desea quitar el Cliente para la ruta?')) {
                        opener.globalRoutesManager.allClientsList[index].checked = false;
                        refreshAllClients();
                    }
                }
            }
            else {
                index = RoutesManager.getIndexClientID(opener.globalRoutesManager.allClientsList, args.getDataKeyValue("ClientID"));
                if (index != -1) {
                    opener.objMapControl.setCenterMap(opener.globalRoutesManager.allClientsList[index].position);
                }
            }
        }

        function refreshAllClients() {
            RoutesManager.clearNumPosClients(opener);
            RoutesManager.clearKmsAndDurationClients(opener, true);
            opener.globalRoutes.isClear = true;
            RoutesManager.loadAllClientsByCompanyIDDataSource(getClientsRoutesGrid(), opener.globalRoutesManager.allClientsList, opener.globalRoutesManager.allClientsDataSource, opener);
            getClientsRoutesGrid().clearSelectedItems();
            RoutesManager.loadAllClientsSelectedDataSource(getClientsRoutesSelectedGrid(), opener.globalRoutesManager.allClientsList, opener.globalRoutesManager.allClientsDataSource, opener);
            getClientsRoutesSelectedGrid().clearSelectedItems();
            opener.globalRoutes.isClear = false;
        }

        function generateRoutes() {
            opener.globalRoutes.cantErrors = 0;
            requestStart(getrpvRoutesManagerPanelUpdateControl());
            
            opener.globalRoutes.totallyClients = RoutesManager.getCantClientSelected(opener);
            if (opener.globalRoutesManager.gpsImeiSelected != -1) {
                if (opener.globalRoutes.totallyClients > 1) {
                    opener.globalRoutes.clientsRoutesSelectedTableView = getClientsRoutesSelectedGrid();

                    refreshAllClients();
                    opener.objMapControl.clientsRoutes = [];
                    opener.globalRoutes.firstClientRoute = true;

                    clearDataSource(opener.globalRoutesManager.allClientsSelectedDataSource, getClientsRoutesSelectedGrid(), true);
                    opener.globalRoutes.numPos = 0;
                    RoutesManager.clearNumPosClients(opener);

                    opener.globalRoutes.updatePanelObject = getrpvRoutesManagerPanelUpdateControl();
                    opener.globalRoutes.responseEndObject = getResponseEnd();
                    opener.globalRoutes.btnGenerateRoute = btnGenerateRoute();
                    opener.globalRoutes.btnGenerateRoute.value = "Cliente 1 de " + opener.globalRoutes.totallyClients;
                    opener.objMapControl.calculateSmartRoute(null);

                }
                else {
                    msgValidation("Debe seleccionar almenos dos clientes para generar la ruta", titles.routesAdministrator, lenghMsg);
                    responseEnd(getrpvRoutesManagerPanelUpdateControl());
                }
            }
            else {
                msgValidation("Debe seleccionar un GPS para iniciar el cálculo de Ruta", titles.routesAdministrator, lenghMsg);
                responseEnd(getrpvRoutesManagerPanelUpdateControl());
            }
        }


        function saveRoutes() {
            if (getBeginDateSelected().get_textBox().value != "") {

                var date = getFormatDate(getBeginDateSelected().get_textBox().value);

                var clientsList = [];
                var numPosList = [];
                var distanceList = [];
                var durationList = [];

                for (i = 0; i < opener.globalRoutesManager.allClientsList.length; i++) {
                    if (opener.globalRoutesManager.allClientsList[i].checked && opener.globalRoutesManager.allClientsList[i].numPos != null) {
                        clientsList.push(opener.globalRoutesManager.allClientsList[i].clientID.toString());
                        numPosList.push(opener.globalRoutesManager.allClientsList[i].numPos.toString());
                        distanceList.push(opener.globalRoutesManager.allClientsList[i].kmsText);
                        durationList.push(opener.globalRoutesManager.allClientsList[i].durationText);
                    }
                }

                if (clientsList.length > 1) {
                    requestStart(getrpvRoutesManagerPanelUpdateControl());
                    PageMethods.wsClientsToVisitInsert(opener.globalRoutesManager.companyIDSelected, opener.globalRoutesManager.usernameSelected, opener.globalRoutesManager.gpsImeiSelected, date, clientsList, numPosList, distanceList, durationList, saveRoutesOk, saveRoutesError);
                }
                else {
                    msgValidation("No hay clientes para visita para guardar.", titles.routesAdministrator, lenghMsg);
                }
            }
            else {
                msgValidation("Se debe seleccionar una fecha.", titles.routesAdministrator, lenghMsg);
            }
        }

        function saveRoutesOk(object)
        {
            msgInformation("Se registraron los clientes de forma satisfactoria.", titles.routesAdministrator, lenghMsg);
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
        }

        function saveRoutesError(error)
        {
            responseEnd(getrpvRoutesManagerPanelUpdateControl());
            msgError(error.get_message(), titles.routesAdministrator);
        }

        function getUsersRoutesGrid() {
            return $find("<%= rgUsersRoutesGrid.ClientID %>").get_masterTableView();
        }

        function btnGenerateRoute() {
            return $get('btnGenerateRoute');
        }

        function getCompaniesGrid() {
            return $find("<%= rgCompaniesGrid.ClientID %>").get_masterTableView();
        }

        function getDeparmentsGrid() {
            return $find("<%= rgDepartmentsGrid.ClientID %>").get_masterTableView();
        }

        function getClientsRoutesGrid() {
            return $find("<%= rgClientsRoutesGrid.ClientID %>").get_masterTableView(); 
        }

        function getClientsRoutesSelectedGrid() {
            return $find("<%= rgClientsRoutesSelectedGrid.ClientID %>").get_masterTableView();
        }

        function getUsersGroupsGrid() {
            return $find("<%= rgUsersGroupsGrid.ClientID %>").get_masterTableView();
        }

        function getGpsRoutesGrid() {
            return $find("<%= rgGpsRoutesGrid.ClientID %>").get_masterTableView();
        }

        function getrpvRoutesManagerPanelUpdateControl() {
            return "<%= rpvRoutesManager.ClientID %>";
        }

        function getBeginDateSelected() {
            return $find('<%= beginDateSelected.ClientID %>');
        }

        function requestStart(object) {
            try {
                $find("<%= RadAjaxLoadingPanel1.ClientID%>").show(object);
            }
            catch (e) {
                null;
            }
        }

        function getResponseEnd() {
            try {
                return $find("<%= RadAjaxLoadingPanel1.ClientID%>");
            }
            catch (e) {
                null;
            }
        }

        function responseEnd(object) {
            try {
                $find("<%= RadAjaxLoadingPanel1.ClientID%>").hide(object);
            }
            catch (e) {
                null;
            }
        }




    </script>
</telerik:RadScriptBlock>
<body onload="loadInfo()">
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"  EnablePageMethods="true" EnablePartialRendering="true"></telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
				<telerik:AjaxSetting AjaxControlID="AjaxControlID1">
					<UpdatedControls>
						<telerik:AjaxUpdatedControl ControlID="Loading" LoadingPanelID="RadAjaxLoadingPanel1" />
					</UpdatedControls>
				</telerik:AjaxSetting>
			</AjaxSettings>
        </telerik:RadAjaxManager>
        
        
        <telerik:RadTabStrip ID="rtsRoutesManager" runat="server" SelectedIndex="0" MultiPageID="rmpRoutesManager" Skin="Metro"></telerik:RadTabStrip>
        <telerik:RadMultiPage ID="rmpRoutesManager" runat="server" SelectedIndex="0">
            <telerik:RadPageView ID="rpvRoutesManager" runat="server">
				<table style=" text-align: left">
					<tr>
                       <td>
							<fieldset>
								<legend>Compañias</legend>
								<telerik:RadGrid ID="rgCompaniesGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" OnNeedDataSource="rgCompaniesGrid_NeedDataSource" Skin="Metro">
									<ClientSettings>
										<Selecting AllowRowSelect="True" />
										<ClientEvents OnRowClick="CompaniesGrid_OnRowClick" />
										<Scrolling AllowScroll="True" UseStaticHeaders="False" />
									</ClientSettings>
									<MasterTableView ClientDataKeyNames="CompanyID" NoMasterRecordsText="No hay Compañias registradas">
										<CommandItemSettings ExportToPdfText="Export to PDF" />
										<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
										</RowIndicatorColumn>
										<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
										</ExpandCollapseColumn>
										<Columns>
											<telerik:GridBoundColumn DataField="CompanyID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="CompanyID" Visible="false">
											</telerik:GridBoundColumn>
											<telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
											</telerik:GridBoundColumn>
										</Columns>
										<EditFormSettings>
											<EditColumn FilterControlAltText="Filter EditCommandColumn column">
											</EditColumn>
										</EditFormSettings>
									</MasterTableView>
									<FilterMenu EnableImageSprites="true">
									</FilterMenu>
								</telerik:RadGrid>
							</fieldset>
						</td> 
					</tr>
                    <tr>
                        <td>
							<fieldset>
								<legend>Departamentos</legend>
								<telerik:RadGrid ID="rgDepartmentsGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" OnNeedDataSource="rgDepartmentsGrid_NeedDataSource" Skin="Metro">
									<ClientSettings>
										<Selecting AllowRowSelect="True" />
										<ClientEvents OnRowClick="DepartmentsGrid_OnRowClick" />
										<Scrolling AllowScroll="True" UseStaticHeaders="False" />
									</ClientSettings>
									<MasterTableView ClientDataKeyNames="DepartmentID" NoMasterRecordsText="No hay Departamentos registrados">
										<CommandItemSettings ExportToPdfText="Export to PDF" />
										<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
										</RowIndicatorColumn>
										<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
										</ExpandCollapseColumn>
										<Columns>
											<telerik:GridBoundColumn DataField="DepartmentID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="DepartmentID" Visible="false">
											</telerik:GridBoundColumn>
											<telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
											</telerik:GridBoundColumn>
										</Columns>
										<EditFormSettings>
											<EditColumn FilterControlAltText="Filter EditCommandColumn column">
											</EditColumn>
										</EditFormSettings>
									</MasterTableView>
									<FilterMenu EnableImageSprites="true">
									</FilterMenu>
								</telerik:RadGrid>
							</fieldset>
						</td>
                    </tr>
                    <tr>
                        <td>
							<fieldset>
								<legend>Grupo de Usuarios</legend>
								<telerik:RadGrid ID="rgUsersGroupsGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" OnNeedDataSource="rgUsersGroupsGrid_NeedDataSource" Skin="Metro" >
									<ClientSettings>
										<Selecting AllowRowSelect="True" />
										<ClientEvents OnRowClick="UsersGroupsGrid_OnRowClick" />
										<Scrolling AllowScroll="True" UseStaticHeaders="False" />
									</ClientSettings>
									<MasterTableView ClientDataKeyNames="UserGroupID" NoMasterRecordsText="No hay Grupos registrados">
										<CommandItemSettings ExportToPdfText="Export to PDF" />
										<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
										</RowIndicatorColumn>
										<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
										</ExpandCollapseColumn>
										<Columns>
											<telerik:GridBoundColumn DataField="UserGroupID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="UserGroupID" Visible="false">
											</telerik:GridBoundColumn>
											<telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
											</telerik:GridBoundColumn>
										</Columns>
										<EditFormSettings>
											<EditColumn FilterControlAltText="Filter EditCommandColumn column">
											</EditColumn>
										</EditFormSettings>
									</MasterTableView>
									<FilterMenu EnableImageSprites="true">
									</FilterMenu>
								</telerik:RadGrid>
							</fieldset>
						</td>
                    </tr>
                    <tr>
                        <td>
							<fieldset>
								<legend>Usuarios</legend>
								<telerik:RadGrid ID="rgUsersRoutesGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" OnNeedDataSource="rgUsersRoutesGrid_NeedDataSource" Skin="Metro" >
									<ClientSettings>
										<Selecting AllowRowSelect="True" />
										<ClientEvents OnRowClick="UsersRoutesGrid_OnRowClick" />
										<Scrolling AllowScroll="True" UseStaticHeaders="False" />
									</ClientSettings>
									<MasterTableView ClientDataKeyNames="Username" NoMasterRecordsText="No hay usuarios registrados">
										<CommandItemSettings ExportToPdfText="Export to PDF" />
										<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
										</RowIndicatorColumn>
										<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
										</ExpandCollapseColumn>
										<Columns>
											<telerik:GridBoundColumn DataField="Username" FilterControlAltText="Filter Description column" HeaderText="Username" UniqueName="Username" Visible="false">
											</telerik:GridBoundColumn>
											<telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
											</telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="FirstName" FilterControlAltText="Filter Description column" HeaderText="Apellido1" Visible="true">
											</telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="LastName" FilterControlAltText="Filter Description column" HeaderText="Apellido2" Visible="true">
											</telerik:GridBoundColumn>
										</Columns>
										<EditFormSettings>
											<EditColumn FilterControlAltText="Filter EditCommandColumn column">
											</EditColumn>
										</EditFormSettings>
									</MasterTableView>
									<FilterMenu EnableImageSprites="true">
									</FilterMenu>
								</telerik:RadGrid>
							</fieldset>
						</td>
                    </tr>
                    <tr>
                        <td>
							<fieldset>
								<legend>GPS Registrados</legend>
								<telerik:RadGrid ID="rgGpsRoutesGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" OnNeedDataSource="rgGpsRoutesGrid_NeedDataSource" Skin="Metro" >
									<ClientSettings>
										<Selecting AllowRowSelect="True" />
										<ClientEvents OnRowClick="GpsRoutesGrid_OnRowClick" />
										<Scrolling AllowScroll="True" UseStaticHeaders="False" />
									</ClientSettings>
									<MasterTableView ClientDataKeyNames="GPSImei" NoMasterRecordsText="No hay gps registrados">
										<CommandItemSettings ExportToPdfText="Export to PDF" />
										<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
										</RowIndicatorColumn>
										<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
										</ExpandCollapseColumn>
										<Columns>
											<telerik:GridBoundColumn DataField="GPSImei" FilterControlAltText="Filter Description column" HeaderText="GPSImei" UniqueName="GPSImei" Visible="false">
											</telerik:GridBoundColumn>
											<telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Description column" HeaderText="Nombre" Visible="true">
											</telerik:GridBoundColumn>
										</Columns>
										<EditFormSettings>
											<EditColumn FilterControlAltText="Filter EditCommandColumn column">
											</EditColumn>
										</EditFormSettings>
									</MasterTableView>
									<FilterMenu EnableImageSprites="true">
									</FilterMenu>
								</telerik:RadGrid>
							</fieldset>
						</td>
                    </tr>
                    <tr>
                        <td>
							<fieldset>
								<legend>Clientes Registrados</legend>
								<telerik:RadGrid ID="rgClientsRoutesGrid" runat="server" AllowMultiRowSelection="true" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" OnNeedDataSource="rgClientsRoutesGrid_NeedDataSource" Skin="Metro" >
									<ClientSettings>
										<Selecting AllowRowSelect="True" />
										<ClientEvents OnRowClick="" OnRowSelecting="ClientsRoutesGrid_RowSelecting" OnRowDeselecting="ClientsRoutesGrid_RowDeselecting" />
										<Scrolling AllowScroll="True" UseStaticHeaders="False" />
									</ClientSettings>
									<MasterTableView ClientDataKeyNames="ClientID" NoMasterRecordsText="No hay clientes registrados">
										<CommandItemSettings ExportToPdfText="Export to PDF" />
										<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
										</RowIndicatorColumn>
										<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
										</ExpandCollapseColumn>
										<Columns>
                                            <telerik:GridBoundColumn DataField="ClientID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="ClientID" Visible="false">
											</telerik:GridBoundColumn>
											<telerik:GridBoundColumn DataField="ClientName" FilterControlAltText="Filter Description column" HeaderText="Cliente" Visible="true">
											</telerik:GridBoundColumn>
											<telerik:GridBoundColumn DataField="ClientGroupName" FilterControlAltText="Filter Description column" HeaderText="Grupo" Visible="true">
											</telerik:GridBoundColumn>
                                            <telerik:GridClientSelectColumn HeaderText="Seleccionar" UniqueName="chkSelectCustomer">
											</telerik:GridClientSelectColumn>
										</Columns>
										<EditFormSettings>
											<EditColumn FilterControlAltText="Filter EditCommandColumn column">
											</EditColumn>
										</EditFormSettings>
									</MasterTableView>
									<FilterMenu EnableImageSprites="true">
									</FilterMenu>
								</telerik:RadGrid>
							</fieldset>
						</td>
                    </tr>
                    <tr>
                        <td>
							<fieldset>
								<legend>Clientes Asociados</legend>
								<telerik:RadGrid ID="rgClientsRoutesSelectedGrid" runat="server" AllowMultiRowSelection="False" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" Height="100px" OnNeedDataSource="rgClientsRoutesSelectedGrid_NeedDataSource" Skin="Metro" Width="430px" >
									<ClientSettings>
										<Selecting AllowRowSelect="True" />
										<ClientEvents OnRowClick="ClientsRoutesSelectedGrid_OnRowClick" OnRowDeselecting="" OnRowSelecting="" />
										<Scrolling AllowScroll="True" UseStaticHeaders="False" />
									</ClientSettings>
									<MasterTableView ClientDataKeyNames="ClientID" NoMasterRecordsText="No hay clientes registrados">
										<CommandItemSettings ExportToPdfText="Export to PDF" />
										<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
										</RowIndicatorColumn>
										<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
										</ExpandCollapseColumn>
										<Columns>
                                            <telerik:GridImageColumn ImageUrl="..\Template\Icons\16px\Delete.gif" UniqueName="DeleteColumn">
											</telerik:GridImageColumn>
                                            <telerik:GridBoundColumn DataField="ClientID" FilterControlAltText="Filter Description column" HeaderText="ID" UniqueName="ClientID" Visible="false">
											</telerik:GridBoundColumn>
											<telerik:GridBoundColumn DataField="NumPos" FilterControlAltText="Filter Description column" HeaderText="Orden" Visible="true">
											</telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="ClientName" FilterControlAltText="Filter Description column" HeaderText="Cliente" Visible="true">
											</telerik:GridBoundColumn>
											<telerik:GridBoundColumn DataField="ClientGroupName" FilterControlAltText="Filter Description column" HeaderText="Grupo" Visible="true">
											</telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="KmsText" FilterControlAltText="Filter Description column" HeaderText="Distancia" Visible="true">
											</telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="DurationText" FilterControlAltText="Filter Description column" HeaderText="Duración" Visible="true">
											</telerik:GridBoundColumn>
										</Columns>
										<EditFormSettings>
											<EditColumn FilterControlAltText="Filter EditCommandColumn column">
											</EditColumn>
										</EditFormSettings>
									</MasterTableView>
									<FilterMenu EnableImageSprites="true">
									</FilterMenu>
								</telerik:RadGrid>
							</fieldset>
						</td>
                    </tr>
                    <tr>
                        <td>
							<fieldset>
								<legend>Asociación de Clientes</legend>
								<table>
                                    <tr>
										<td>
											<input id="btnClients" type="button" value="Asociar Cliente" onclick="refreshAllClients();" />
										</td>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
										<td>
											<input id="btnGenerateRoute" type="button" value="Generar Rutas" onclick="generateRoutes();" />
										</td>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
									</tr>
								</table>
							</fieldset>
						</td>
                    </tr>
                    <tr>
                        <td>
							<fieldset>
								<legend>Guardar Orden de Clientes de Visita</legend>
								<table>
                                    <tr>
                                        <td>
                                        <telerik:RadDatePicker ID="beginDateSelected" runat="server" DateInput-Label="Fecha Desde" style="text-align: left" Height="24px" Width="200px">
							                <Calendar UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x"></Calendar>
			                                <DateInput DateFormat="dd/MM/yyyy" DisplayDateFormat="dd/MM/yyyy" Height="24px" LabelWidth="50%"></DateInput>
		                                </telerik:RadDatePicker>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
										<td>
											<input id="btnSaveRoutes" type="button" value="Guardar Rutas" onclick="saveRoutes();" />
										</td>
									</tr>
								</table>
							</fieldset>
						</td>
                    </tr>
				</table>
            </telerik:RadPageView>
        </telerik:RadMultiPage>

        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default"></telerik:RadAjaxLoadingPanel>
    </form>
</body>
</html>
